{extend name="Base" /}
{block name="title"}{$title}{/block}
{block name="body"}
{load href="/tinymce/tinymce.min.js"}
<form action="/index/edit/doEdit" method="post" class="am-container am-g am-form" enctype="multipart/form-data" role="form">
	<fieldset>
		<legend>{$title}</legend>

		<table class="am-table am-table-bordered am-table-radius">
			<tbody>
			<tr>
				<td class="am-text-middle am-text-center am-text-nowrap" colspan="2">无需改动的选项保持原样即可</td>
			</tr>
			<tr>
				<td class="am-text-middle am-text-right am-text-nowrap">*分类</td>
				<td>
					<label>
						<select onclick="selectChange(this.value)"
								data-am-selected="{maxHeight: 200, searchBox: 1, btnStyle: 'primary'}"
								placeholder="请选择分类"
								id="olcate" name="olcate">
						</select>
					</label>
					<label>
						<select
							data-am-selected="{maxHeight: 200, searchBox: 1, btnStyle: 'secondary'}"
							placeholder="请选择二级分类"
							id="slcate" name="slcate">
						</select>
					</label>
				</td>
			</tr>
			<tr class="album" style="display: none">
				<td class="am-text-middle am-text-right am-text-nowrap">检索聚合</td>
				<td>
					<div class="am-input-group">
						<input type="text" class="am-form-field" name="searchalbumname" placeholder="请务必使用正式发布的名称进行精确检索">
						<i class="am-input-group-btn">
							<button class="am-btn am-btn-default searchalbumname" type="button"><i class="am-icon-search" title="检索"></i></button>
						</i>
					</div>
				</td>
			</tr>
			<tr>
				<td class="am-text-middle am-text-right am-text-nowrap" id="maintitle">*主标题</td>
				<td>
					<input type="text" class="am-form-field maintitle" name="maintitle" placeholder="主标题" value="{$torrent.maintitle}"/>
					<div style="color: #989898;">电影：Assassin's.Creed.2016.BluRay.1080p.AVC.DTS-HD.MA7.1-SGNB</div>
					<div style="color: #989898;">剧集：Criminal.Minds.S12E12.720p.HDTV.x264-FLEET</div>
				</td>
			</tr>
			<tr class="album" style="display: none">
				<td class="am-text-middle am-text-right am-text-nowrap">*聚合名称</td>
				<td>
					<input type="text" class="am-form-field albumname" name="albumname" placeholder="集合、季的名称"/>
					<div style="color: #989898;">剧集："Criminal.Minds" 或 "犯罪心理"，建议使用英文名称</div>
					<div style="color: #989898;">音乐："叶惠美"</div>
					<div style="color: #989898;">注意：隔断请使用点｛.｝或圆括号｛()｝来分割</div>
				</td>
			</tr>
			<tr>
				<td class="am-text-middle am-text-right am-text-nowrap" id="subtitle">副标题</td>
				<td>
					<input type="text" class="am-form-field subtitle" name="subtitle" placeholder="副标题、季集的名称" value="{$torrent.subtitle}"/>
					<div style="color: #989898;">电影：刺客信条/刺客教条(港/台) [原盘DIY BDJ菜单修改 次时代国语音轨 国配简英繁特效四字幕]</div>
					<div style="color: #989898;">整季：Seasion 12</div>
					<div style="color: #989898;">单集：S12E12</div>
					<div style="color: #989898;">音乐：FLAC、APE、320K、128K等</div>
				</td>
			</tr>
			<tr>
				<td class="am-text-middle am-text-right am-text-nowrap">制作方</td>
				<td>
					<select
						data-am-selected="{maxHeight: 200, searchBox: 1, btnStyle: 'primary'}"
						placeholder="请选择制作方"
						id="author" name="author">
						<option selected value=""></option>
						<option value="0">&nbsp;</option>
					</select>
				</td>
			</tr>
			<tr id="logchecker" style="display: none">
				<td class="am-text-middle am-text-right am-text-nowrap">LogChecker</td>
				<td>
					<div class="am-input-group">
						<span class="am-input-group-label logcheckerscore" title="评分">0</span>
						<input type="hidden" name="logscore" value=""/>
						<textarea name="logchecker" placeholder="填写LogChecker，点击右侧按钮可自动评分" title="" class="am-form-field"></textarea>
						<i class="am-input-group-btn">
							<button class="am-btn am-btn-default logchecker" type="button"><i class="am-icon-music" title="获取LogChecker评分"></i></button>
						</i>
					</div>
				</td>
			</tr>
			<tr id="imdb">
				<td class="am-text-middle am-text-right am-text-nowrap">IMDb链接</td>
				<td>
					<input type="text" class="am-form-field" name="imdburl" placeholder="IMDb链接，填写后可以获取IMDb评分"/>
				</td>
			</tr>
			<tr id="douban">
				<td class="am-text-middle am-text-right am-text-nowrap">豆瓣链接</td>
				<td>
					<div class="am-input-group">
						<input type="text" class="am-form-field" name="doubanurl" placeholder="豆瓣链接，点击右侧按钮可自动填写详情信息">
						<i class="am-input-group-btn">
							<button class="am-btn am-btn-default getdouban" type="button"><i class="am-icon-clone" title="自动获取"></i></button>
						</i>
					</div>
				</td>
			</tr>
			{if condition="$access eq 1"}
			<tr id="sticklevel">
				<td class="am-text-middle am-text-right am-text-nowrap">置顶选项</td>
				<td class="am-form-inline">
					<div class="am-form-group">
						<select
							data-am-selected="{maxHeight: 200, btnStyle: 'primary'}"
							placeholder="请选择置顶等级" name="sticklevel">
							<option selected value=""></option>
							<option value="0">&nbsp;</option>
							<option value="1">1级置顶</option>
							<option value="2">2级置顶</option>
							<option value="3">3级置顶</option>
						</select>
					</div>
					<div class="am-form-group">
						<input type="text" class="am-form-field" name="sticktime" placeholder="置顶时长，单位：小时">
					</div>
					<div style="color: #989898;">选择置顶等级且不填写时长则默认6小时；0=永久{php}$torrent['sticktime'] == 0 && !empty($torrent['sticklevel']) ? print("。当前为永久") : ($torrent['sticktime'] != 0 && !empty($torrent['sticklevel']) ? print("。当前持续至 " . $torrent['sticktime'] . "") : ""){/php}</div>
				</td>
			</tr>
			<tr id="discount">
				<td class="am-text-middle am-text-right am-text-nowrap">优惠选项</td>
				<td class="am-form-inline">
					<div class="am-form-group">
						<select
							data-am-selected="{maxHeight: 200, btnStyle: 'primary'}"
							placeholder="请选择优惠力度" name="discount">
							<option selected value=""></option>
							<option value="0">&nbsp;</option>
							<option value="1">Free</option>
							<option value="2">30%</option>
							<option value="3">50%</option>
							<option value="4">2x</option>
							<option value="5">2xFree</option>
							<option value="6">2x30%</option>
							<option value="7">2x50%</option>
						</select>
					</div>
					<div class="am-form-group">
						<input type="text" class="am-form-field" name="discounttime" placeholder="优惠时长，单位：小时">
					</div>
					<div style="color: #989898;">选择优惠力度且不填写时长则默认6小时；0=永久{php}$torrent['discounttime'] == 0 && !empty($torrent['discount']) ? print("。当前为永久") : ($torrent['discounttime'] != 0 && !empty($torrent['discount']) ? print("。当前持续至 " . $torrent['discounttime'] . "") : ""){/php}</div>
				</td>
			</tr>
			{/if}
			<tr>
				<td class="am-text-middle am-text-right am-text-nowrap">额外选项</td>
				<td>
					{if condition="$access eq 1"}
					<label class="am-checkbox-inline">
						<input type="checkbox" name="official" value="1" data-am-ucheck><span class="am-badge am-radius official">官方</span>
					</label>
					<label class="am-checkbox-inline">
						<input type="checkbox" name="excl" value="1" data-am-ucheck><span class="am-badge am-radius excl">独占</span>
					</label>
					<label class="am-checkbox-inline">
						<input type="checkbox" name="first" value="1" data-am-ucheck><span class="am-badge am-radius first">首发</span>
					</label>
					<label class="am-checkbox-inline">
						<input type="checkbox" name="hr" value="1" data-am-ucheck><span class="am-badge am-radius hr">H&R</span>
					</label>
					{/if}
					<label class="am-checkbox-inline">
						<input type="checkbox" name="anonymous" value="1" data-am-ucheck> 匿名
					</label>
				</td>
			</tr>
			<tr>
				<td class="am-text-middle am-text-right am-text-nowrap">*?附加选项</td>
				<td>
					<label>
						<select
							data-am-selected="{maxHeight: 200, searchBox: 1, btnStyle: 'primary'}"
							placeholder="请选择封装类型"
							id="container" name="container">
							<option selected value=""></option>
							<option value="0">&nbsp;</option>
						</select>
					</label>
					<label>
						<select
							data-am-selected="{maxHeight: 200, searchBox: 1, btnStyle: 'primary'}"
							placeholder="请选择获取源类型"
							id="source" name="source">
							<option selected value=""></option>
							<option value="0">&nbsp;</option>
						</select>
					</label>
					<label>
						<select
							data-am-selected="{maxHeight: 200, searchBox: 1, btnStyle: 'primary'}"
							placeholder="请选择分辨率"
							id="resolution" name="resolution">
							<option selected value=""></option>
							<option value="0">&nbsp;</option>
						</select>
					</label>
					<div style="color: #989898;">注意：非电影大类时为必选项，无相应选项则选空</div>
				</td>
			</tr>
			<tr>
				<td class="am-text-right am-text-nowrap">*详情</td>
				<td><textarea id="editor" name="descs" title="详情">{$torrent.descs}</textarea></td>
			</tr>

			{:token()}

			<input type="hidden" name="torrentid" value="{$torrent.id}"/>
			<input type="hidden" name="torrenttype" value="{$torrent.type}"/>

			</tbody>
		</table>
		<button class="am-btn am-btn-secondary am-center submit" type="submit">提交</button>
	</fieldset>
</form>

<div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">
	<div class="am-modal-dialog">
		<div class="am-modal-bd"></div>
		<div class="am-modal-footer">
			<span class="am-modal-btn" data-am-modal-confirm>知道了</span>
		</div>
	</div>
</div>

<script>
	$.ajax({
		type: "POST",
		url: "/index/Edit/getCategory",
		cache: false,
		data: {
			id: $("input[name=torrentid]").val(),
			type: $("input[name=torrenttype]").val()
		},
		dataType: "json",
		success: function (data) {
			if (Number(data.data.official) === 1) {
				$("input[name=official]").attr("checked", "checked");
			}
			if (Number(data.data.excl) === 1) {
				$("input[name=excl]").attr("checked", "checked");
			}
			if (Number(data.data.first) === 1) {
				$("input[name=first]").attr("checked", "checked");
			}
			if (Number(data.data.hr) === 1) {
				$("input[name=hr]").attr("checked", "checked");
			}
			if (Number(data.data.anonymous) === 1) {
				$("input[name=anonymous]").attr("checked", "checked");
			}

			var $album = $(".album");
			var $subtitle = $("#subtitle");
			var $albumname = $(".albumname");
			var $olcate = $("#olcate");
			var $slcate = $("#slcate");
			var $author = $("#author");
			var $logchecker = $("#logchecker");
			if (data.status === 1) {
				if (data.data.olcate !== 1) {
					var $imdb = $("#imdb");
					var $douban = $("#douban");
					if (data.data.olcate === 3) {
						$imdb.css("display", "none");
						$douban.css("display", "none");
						$logchecker.css("display", "");
						$(".logcheckerscore").html(data.data.logscore);
					} else {
						$imdb.css("display", "");
						$douban.css("display", "");
						$logchecker.css("display", "none");
					}
					$subtitle.html("*季集名称");
					$album.css("display", "");
					$albumname.attr("value", data.data.albumname);
				}
				//容器类型
				var container = data.data.t_container;
				for (var i_container in container) {
					var o_container = $("<option></option>");
					$(o_container).val(container[i_container]['id']);
					$(o_container).html(container[i_container]['name']);
					if (container[i_container]['id'] === data.data.container) {
						$(o_container).attr("selected", "selected");
					}
					$("#container").append(o_container);
				}
				//分辨率
				var resolution = data.data.t_resolution;
				for (var i_resolution in resolution) {
					var o_resolution = $("<option></option>");
					$(o_resolution).val(resolution[i_resolution]['id']);
					$(o_resolution).html(resolution[i_resolution]['name']);
					if (resolution[i_resolution]['id'] === data.data.resolution) {
						$(o_resolution).attr("selected", "selected");
					}
					$("#resolution").append(o_resolution);
				}
				//获取源类型
				var source = data.data.t_source;
				for (var i_source in source) {
					var o_source = $("<option></option>");
					$(o_source).val(source[i_source]['id']);
					$(o_source).html(source[i_source]['name']);
					if (source[i_source]['id'] === data.data.source) {
						$(o_source).attr("selected", "selected");
					}
					$("#source").append(o_source);
				}
				//一级分类
				var olcate = data.data.t_olcate;
				for (var i_olcate in olcate) {
					var o_olcate = $("<option></option>");
					$(o_olcate).val(olcate[i_olcate]['id']);
					$(o_olcate).html(olcate[i_olcate]['name']);
					if (olcate[i_olcate]['id'] === data.data.olcate) {
						$(o_olcate).attr("selected", "selected");
					}
					$olcate.append(o_olcate);
				}
				//二级分类
				var slcate = data.data.t_slcate;
				for (var i_slcate in slcate) {
					var o_slcate = $("<option></option>");
					$(o_slcate).val(slcate[i_slcate]['id']);
					$(o_slcate).html(slcate[i_slcate]['name']);
					if (slcate[i_slcate]['id'] === data.data.slcate) {
						$(o_slcate).attr("selected", "selected");
					}
					$slcate.append(o_slcate);
				}
				//制作方
				var author = data.data.t_author;
				for (var i_author in author) {
					var o_author = $("<option></option>");
					$(o_author).val(author[i_author]['id']);
					$(o_author).html(author[i_author]['author']);
					if (author[i_author]['id'] === data.data.author) {
						$(o_author).attr("selected", "selected");
					}
					$author.append(o_author);
				}
				//置顶等级
				$("#sticklevel li").each(function () {
					var value = $(this).attr("data-value");
					var html = $(this).find("span").html();
					if (Number(value) !== 0 && Number(value) === Number(data.data.sticklevel)) {
						$(this).addClass("am-checked");
						$("#sticklevel button span").html(html);
					}
				});
				$("#sticklevel option").each(function () {
					if (Number($(this).val()) === Number(data.data.sticklevel)) {
						$(this).attr("selected", "selected");
					}
				});
				//优惠等级
				$("#discount li").each(function () {
					var value = $(this).attr("data-value");
					var html = $(this).find("span").html();
					if (Number(value) !== 0 && Number(value) === Number(data.data.discount)) {
						$(this).addClass("am-checked");
						$("#discount button span").html(html);
					}
				});
				$("#discount option").each(function () {
					if (Number($(this).val()) === Number(data.data.discount)) {
						$(this).attr("selected", "selected");
					}
				});
			}
		}
	});

	$(".getdouban").click(function () {
		var data = {
			wd: $("input[name=doubanurl]").val()
		};

		$.ajax({
			type: "POST",
			url: "/index/Release/getDouBan",
			cache: false,
			data: data,
			dataType: "json",
			success: function (data) {
				tinymce.activeEditor.setContent(data);
			}
		});
	});

	$(".logchecker").click(function () {
		var data = {
			log: $("textarea[name=logchecker]").val()
		};

		$.ajax({
			type: "POST",
			url: "/index/Release/getLogCheckerScore",
			cache: false,
			data: data,
			dataType: "json",
			success: function (data) {
				$(".logcheckerscore").html(data.data.logscore);
				$("input[name=logscore]").val(data.data.logscore);
				$("textarea[name=logchecker]").val("");
			}
		});
	});

	$(".searchalbumname").click(function () {
		var data = {
			searchalbumname: $("input[name=searchalbumname]").val()
		};

		$.ajax({
			type: "POST",
			url: "/index/release/queryAlbum",
			cache: false,
			data: data,
			dataType: "json",
			success: function (data) {
				var $albumname = $(".albumname");
				if (data.status === 1) {
					$albumname.attr("value", data.data);
					$albumname.attr("readonly", "readonly");
				} else {
					$albumname.removeAttr("value");
					$albumname.removeAttr("readonly");
				}
			}
		});
	});

	function selectChange(id) {
		var data = {
			olcate: id
		};

		$.ajax({
			type: "POST",
			url: "/index/release/queryTwoLevelCategory",
			cache: false,
			data: data,
			dataType: "json",
			success: function (data) {
				var $slcate = $("#slcate");
				var $album = $(".album");
				var $subtitle = $("#subtitle");
				var $logchecker = $("#logchecker");
				if (id !== "1") {
					var $imdb = $("#imdb");
					var $douban = $("#douban");
					if (id === "3") {
						$imdb.css("display", "none");
						$douban.css("display", "none");
						$logchecker.css("display", "");
					} else {
						$imdb.css("display", "");
						$douban.css("display", "");
						$logchecker.css("display", "none");
					}
					$subtitle.html("*季集名称");
					$album.css("display", "");
				} else {
					$subtitle.html("*副标题");
					$album.css("display", "none");
					$logchecker.css("display", "none");
				}
				if (data.status === 1) {
					$slcate.empty();
					//级联选择
					var slcate = data.data;
					for (var i in slcate) {
						var option = $("<option></option>");
						$(option).val(slcate[i]['id']);
						$(option).html(slcate[i]['name']);
						$slcate.append(option);
					}
					//级联选择
				} else if (data.status === 0) {
					$(".am-modal-bd").html(data.message);
					$("#my-alert").modal({
						onConfirm: function () {
							location.href = "/index/release";
						}
					});
				} else {
					$slcate.empty();
				}
			}
		});
	}

	tinymce.init({
		language: "zh_CN",
		selector: '#editor',
		height: 400,
		theme: 'modern',
		branding: false,
		plugins: [
			'advlist autolink lists link image charmap print preview hr anchor pagebreak',
			'searchreplace wordcount visualblocks visualchars code fullscreen',
			'insertdatetime media nonbreaking save table contextmenu directionality',
			'emoticons paste textcolor colorpicker textpattern imagetools codesample toc localautosave'
		],
		toolbar: 'undo redo | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image media preview | forecolor backcolor | codesample | localautosave',
		image_advtab: false,//图片高级编辑，比如边距等，建议关闭
		setup: function (editor) {
			editor.addMenuItem('imgbed', {
				text: 'ClanTu图床',
				icon: "mce-ico mce-i-image",
				context: 'tools',
				onclick: function () {
					window.open("http://www.clantu.com/register/i/dAszQ1");
				}
			});
		}
	});
</script>
{/block}